package com.gdwhomework.generic.homework01;

import java.util.*;

/**
 * @author 关道伟
 * @version 1.0
 */
public class DAO<T> {
    private Map<String,T> map = new HashMap<>();

    public T get(String id){
        return map.get(id);
    }

    public void update(String id,T entity){
        map.put(id,entity);
    }

    //遍历map 将map的所有value分装到Arraylist返回即可
    public List<T> list(){
        ArrayList<T> list = new ArrayList<>();

        Set<String> keySet = map.keySet();
        for(String key:keySet){
            list.add(map.get(key));
        }

        return list;
    }

    public void delete(String id){
        map.remove(id);
    }

    public void save(String id,T entity){
        map.put(id,entity);
    }
}
